package com.yugao.fintech.antelope.gateway.model;

import com.alibaba.fastjson2.JSONObject;
import com.yugao.fintech.antelope.gateway.constants.StatisticCons;
import com.yugao.fintech.antelope.base.model.module.mq.AbstractMQ;
import com.yugao.fintech.antelope.base.model.module.mq.BaseMqPayload;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Optional;

/**
 * 消息推送队列
 */
public class StatisticMQ extends AbstractMQ {
    public static final String QUEUE = "statistic.queue";
    public static final String KEY = "statistic.key";
    public static final String EXCHANGE = StatisticCons.EXCHANGE;

    public StatisticMQ(Payload payload) {
        super(payload);
    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    @AllArgsConstructor
    public static class Payload extends BaseMqPayload {
        /**
         * 统计类型 {@link StatisticCons.Type}
         */
        private String type;
        private Long userId;
        private JSONObject data;

        public JSONObject getData() {
            return Optional.ofNullable(data).orElse(new JSONObject());
        }
    }


    /**
     * 构建
     *
     * @param type   类型 {@link StatisticCons.Type}
     * @param userId 用户id
     * @param data   数据, 可选
     */
    public static StatisticMQ build(String type, Long userId, JSONObject data) {
        return new StatisticMQ(new Payload(type, userId, data));
    }

    public static StatisticMQ build(String type, JSONObject data) {
        return new StatisticMQ(new Payload(type, null, data));
    }
}
